package com.starlight.ts_clouddev.util;

import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author yfy2001
 * @date 2023/5/9 21:09
 */
@Component
public class CurrentUserInfoUtils {

   public static final ThreadLocal<Map<String,String>> threadLocal=new ThreadLocal<>();


    private static Map<String, String> getLocalMap() {
        Map<String, String> map = threadLocal.get();
        if (map == null) {
            map = new HashMap<>();
            threadLocal.set(map);
        }
        return map;
    }

    public static void set(String key,String value){
        Map<String, String> map = getLocalMap();
//        System.out.println("key:"+key+",value:"+value);
        map.put(key, value);
    }


    public static String get(String key){
        Map<String, String> map = getLocalMap();
        return map.get(key);
    }

    public static String getIp(){
        Map<String, String> map = getLocalMap();
        return map.get("ip");
    }

    public static String getAddress(){
        Map<String, String> map = getLocalMap();
        return map.get("address");
    }

    public static String getUserId(){
        Map<String, String> map = getLocalMap();
        return map.get("userId");
    }

    public static String getUsername(){
        Map<String, String> map = getLocalMap();
        return map.get("username");
    }




}
